package cloud.tianai.ram.policy.core.condition.impl;

import cloud.tianai.ram.policy.core.action.Action;
import cloud.tianai.ram.policy.core.condition.Condition;
import cloud.tianai.ram.policy.core.condition.ConditionHandler;
import cloud.tianai.ram.policy.core.condition.ConditionHandlerManager;

/**
 * @Author: 天爱有情
 * @date 2022/3/24 14:21
 * @Description 条件组合器  并且
 */
public class AndConditionHandler implements ConditionHandler {
    @Override
    public boolean match(Condition condition, ConditionHandlerManager conditionHandlerManager, Action action) {
        for (Condition child : condition.getChildren()) {
            if (conditionHandlerManager.match(child, action).isDeny()) {
                return false;
            }
        }
        return true;
    }

    @Override
    public String getType() {
        return "and";
    }

    @Override
    public String getDescription() {
        return "并且";
    }
}
